<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceUpdateFacebookID extends core {

    public function process() {
        $user_id = intval($_POST['user_id']);
        $facebook_id = $this->db->escape($_POST['facebook_id']);
        $is_the_first_login_facebook = false;
        $user = $this->db->get_row("SELECT * FROM users WHERE id = {$user_id} LIMIT 1");
       
        if ($user->facebook_id) {
            $is_the_first_login_facebook = false;
            $this->_JSONResponse(array('error' => 0, 'msg' => 'Facebook ID is exist', 'is_the_first_login_facebook' => $is_the_first_login_facebook));
        } else {
            $is_the_first_login_facebook = true;
            $result = $this->db->query("UPDATE `users` SET 
                                            `facebook_id` = '{$facebook_id}'                                           
                                        WHERE id = '{$user_id}'");

            if ($result >= 0) {
                $this->_JSONResponse(array('error' => 0, 'is_the_first_login_facebook' => $is_the_first_login_facebook));
            } else {
                $this->_JSONResponse(array('error' => 1));
            }
        }
    }

}

$processor = new webServiceUpdateFacebookID();
$processor->process();
?>